package com.qingpeng.pay.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.qingpeng.pay.R;
import com.qingpeng.pay.api.Host;
import com.qingpeng.pay.api.RedBag;
import com.qingpeng.pay.base.BaseActivity;
import com.qingpeng.pay.beans.MoneyBean;
import com.qingpeng.pay.okhttp.RetrofitCreateHelper;
import com.qingpeng.pay.utils.APP;
import com.qingpeng.pay.utils.ToastUtils;
import com.qingpeng.pay.views.TitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MoneyActivity extends BaseActivity {


    @BindView(R.id.title)
    TitleBar title;
    @BindView(R.id.user_money)
    TextView userMoney;
    @BindView(R.id.max_money)
    TextView maxMoney;
    @BindView(R.id.money_award)
    TextView moneyAward;
    @BindView(R.id.day_money)
    TextView dayMoney;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_money;
    }

    @Override
    protected int getRootViewId() {
        return 0;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return 0;
    }

    @Override
    protected void onResume() {
        super.onResume();
        title.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        Call<MoneyBean> getaccount = RetrofitCreateHelper.createApi(RedBag.class, Host.HOST).getaccount();
        getaccount.enqueue(new Callback<MoneyBean>() {
            @Override
            public void onResponse(Call<MoneyBean> call, Response<MoneyBean> response) {
                MoneyBean body = response.body();
                if (body.getStatus() != 1) {
                    ToastUtils.showToast(MoneyActivity.this, body.getInfo());
                    return;
                }
                dayMoney.setText(body.getData().getDaybrokerage() + "");
                userMoney.setText(body.getData().getTolscore() + "");
                maxMoney.setText(body.getData().getTolbrokerage() + "");
                moneyAward.setText((APP.userInfo.getRate() * 1000) / 10 + "%");
            }

            @Override
            public void onFailure(Call<MoneyBean> call, Throwable t) {
                ToastUtils.showToast(MoneyActivity.this, "网络请求错误,请稍后重试");
            }
        });
    }

    @OnClick({R.id.miv_money_list,R.id.miv_chongzhi, R.id.miv_chongzhi_list, R.id.miv_tixian, R.id.miv_tixian_list})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.miv_money_list:
                startActivity(new Intent(MoneyActivity.this, MoneyRecordActivity.class));
                break;
            case R.id.miv_chongzhi:
                startActivity(new Intent(MoneyActivity.this, KefuActivity.class));
                break;
            case R.id.miv_chongzhi_list:
                startActivity(new Intent(MoneyActivity.this, MoneyListActivity.class).putExtra("type", "1"));
                break;
            case R.id.miv_tixian:
                startActivity(new Intent(MoneyActivity.this, WithdrawCashActivity.class));
                break;
            case R.id.miv_tixian_list:
                startActivity(new Intent(MoneyActivity.this, MoneyListActivity.class).putExtra("type", "2"));
                break;
        }
    }
}
